package com.knxhd.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.knxhd.entity.LlmModelConfig;
import com.knxhd.pojo.HttpResult;
import com.knxhd.service.LlmModelConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 模型配置(LlmModelConfig)表控制层
 *
 * @author makejava
 * @since 2025-07-19 15:37:56
 */
@RestController
@RequestMapping
@RequiredArgsConstructor
public class LlmModelConfigController {
    /**
     * 服务对象
     */
    private final LlmModelConfigService llmModelConfigService;

    /**
     * 分页查询所有数据
     *
     * @param page           分页对象
     * @param llmModelConfig 查询实体
     * @return 所有数据
     */
    @GetMapping
    public HttpResult<Page<LlmModelConfig>> selectAll(Page<LlmModelConfig> page, LlmModelConfig llmModelConfig) {
        return HttpResult.success(this.llmModelConfigService.page(page, new QueryWrapper<>(llmModelConfig)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public HttpResult<LlmModelConfig> selectOne(@PathVariable Serializable id) {
        return HttpResult.success(this.llmModelConfigService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param llmModelConfig 实体对象
     * @return 新增结果
     */
    @PostMapping
    public HttpResult<Boolean> insert(@RequestBody LlmModelConfig llmModelConfig) {
        return HttpResult.success(this.llmModelConfigService.save(llmModelConfig));
    }

    /**
     * 修改数据
     *
     * @param llmModelConfig 实体对象
     * @return 修改结果
     */
    @PutMapping
    public HttpResult<Boolean> update(@RequestBody LlmModelConfig llmModelConfig) {
        return HttpResult.success(this.llmModelConfigService.updateById(llmModelConfig));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public HttpResult<Boolean> delete(@RequestParam("idList") List<Long> idList) {
        return HttpResult.success(this.llmModelConfigService.removeByIds(idList));
    }
}

